﻿using JSShop.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JSShop.Model
{
    public class OrderInfo
    {
        private decimal adjustedFreigh;
        private IList<Hishop_OrderGifts> gifts;
        private Dictionary<string, Hishop_OrderItems> lineItems;
        public OrderInfo()
        {
            this.OrderStatus = OrderStatus.WaitBuyerPay;
            this.RefundStatus = RefundStatus.None;
        }
        public string Address { get; set; }
        public decimal AdjustedDiscount { get; set; }
        public decimal AdjustedFreight
        {
            get
            {
                return this.adjustedFreigh;
            }
            set
            {
                this.adjustedFreigh = value;
            }
        }
        public int BundlingID { get; set; }

        public int? BundlingNum { get; set; }

        public decimal BundlingPrice { get; set; }

        public string CellPhone { get; set; }

        public string CloseReason { get; set; }

        public int CountDownBuyId { get; set; }

        public decimal CouponAmount { get; set; }

        public string CouponCode { get; set; }

        public string CouponName { get; set; }

        public decimal CouponValue { get; set; }

        public string EmailAddress { get; set; }

        public string ExpressCompanyAbb { get; set; }

        public string ExpressCompanyName { get; set; }

        public DateTime FinishDate { get; set; }

        public decimal Freight { get; set; }

        public int FreightFreePromotionId { get; set; }

        public string FreightFreePromotionName { get; set; }

        public string Gateway { get; set; }

        public string GatewayOrderId { get; set; }

        public IList<Hishop_OrderGifts> Gifts
        {
            get
            {
                if (this.gifts == null)
                {
                    this.gifts = new List<Hishop_OrderGifts>();
                }
                return this.gifts;
            }
        }

        public int GroupBuyId { get; set; }

        public GroupBuyStatus GroupBuyStatus { get; set; }

        public string InvoiceTitle { get; set; }

        public bool IsFreightFree { get; set; }

        public bool IsPrinted { get; set; }

        public bool IsReduced { get; set; }

        public bool IsSendTimesPoint { get; set; }

        public Dictionary<string, Hishop_OrderItems> LineItems
        {
            get
            {
                if (this.lineItems == null)
                {
                    this.lineItems = new Dictionary<string, Hishop_OrderItems>();
                }
                return this.lineItems;
            }
        }

        public OrderMark? ManagerMark { get; set; }

        public string ManagerRemark { get; set; }

        public string ModeName { get; set; }

        public string MSN { get; set; }

        public decimal NeedPrice { get; set; }

        public DateTime OrderDate { get; set; }

        public string OrderId { get; set; }

        public OrderSource OrderSource { get; set; }

        public OrderStatus OrderStatus { get; set; }

        public decimal PayCharge { get; set; }

        public DateTime PayDate { get; set; }

        public string PaymentType { get; set; }

        public int PaymentTypeId { get; set; }

        public int Points { get; set; }

        public string QQ { get; set; }

        public string RealModeName { get; set; }

        public string RealName { get; set; }

        public int RealShippingModeId { get; set; }

        public decimal ReducedPromotionAmount { get; set; }

        public int ReducedPromotionId { get; set; }

        public string ReducedPromotionName { get; set; }

        public decimal RefundAmount { get; set; }

        public string RefundRemark { get; set; }

        public RefundStatus RefundStatus { get; set; }

        public int RegionId { get; set; }

        public string Remark { get; set; }

        public string Sender { get; set; }

        public int SentTimesPointPromotionId { get; set; }

        public string SentTimesPointPromotionName { get; set; }

        public string ShipOrderNumber { get; set; }

        public DateTime ShippingDate { get; set; }

        public int ShippingModeId { get; set; }

        public string ShippingRegion { get; set; }

        public string ShipTo { get; set; }

        public string ShipToDate { get; set; }

        public string TaobaoOrderId { get; set; }

        public string ThumbnaiUrl160 { get; set; }
        public decimal Tax { get; set; }

        public string TelPhone { get; set; }

        public decimal TimesPoint { get; set; }

        public int UserId { get; set; }

        public string Username { get; set; }

        public string Wangwang { get; set; }

        public decimal Weight
        {
            get
            {
                decimal num = 0M;
                foreach (Hishop_OrderItems info in this.LineItems.Values)
                {
                    num += info.Weight.Value * info.ShipmentQuantity;
                }
                return num;
            }
        }

        public string ZipCode { get; set; }

        public decimal GetTotal()
        {
            decimal amount = this.GetAmount();
            if (this.BundlingID > 0)
            {
                amount = this.BundlingPrice;
            }
            if (this.IsReduced)
            {
                amount -= this.ReducedPromotionAmount;
            }
            amount += this.AdjustedFreight;
            amount += this.PayCharge;
            amount += this.Tax;
            if (!string.IsNullOrEmpty(this.CouponCode))
            {
                amount -= this.CouponValue;
            }
            return (amount + this.AdjustedDiscount);
        }

        public decimal GetAmount()
        {
            decimal num = 0M;
            foreach (Hishop_OrderItems info in this.LineItems.Values)
            {
                num += info.GetSubTotal();
            }
            return num;
        }
        public virtual decimal GetCostPrice()
        {
            decimal num = 0M;
            foreach (Hishop_OrderItems info in this.LineItems.Values)
            {
                num += info.CostPrice * info.ShipmentQuantity;
            }
            foreach (Hishop_OrderGifts info2 in this.Gifts)
            {
                num += info2.CostPrice.Value * info2.Quantity.Value;
            }
            return num;
        }
        public virtual decimal GetProfit()
        {
            return ((this.GetTotal() - this.RefundAmount) - this.GetCostPrice());
        }

        public int IsAlreadyPay { get; set; }
    }
}
